package com.mojo.concurrent.concurrent_08_collection;

import java.util.concurrent.ConcurrentHashMap;

/**
 * ConcurrentHashMap使用
 *
 * @author <a href="mailto:mojo_jj@163.com">Mojo</a>
 */
public class ConcurrentHashMapDemo {
    public static void main(String[] args) {
        // map初始化关键参数
        ConcurrentHashMap<Object, Object> map = new ConcurrentHashMap<>(2);
        // 通过CAS和synchronized保证线程安全
        // 1.7之前是分段锁，1.8之后是CAS和synchronized保证线程安全
        map.put("1", "a");
        map.put("2", "a");
        map.put("1", "b");

    }
}
